<!--登录页-->
<template>
  <div id="main-div">
    <el-card style="width: 500px;height: 300px;margin: 0 auto;position:relative;top:100px;background-color:rgba(0,0,0,0); border: 0">
      <el-form label-width="60px">
        <el-form-item label="手机号" style="margin-top:60px;">
          <el-input placeholder="请输入手机号" v-model="user.phoneNumber"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input placeholder="请输入密码" type="password" v-model="user.password"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" style="width: 100px;margin-left:120px;" @click="initValidate">点击验证</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" style="width: 100px;margin-left:120px;" @click="login()">登录</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>
<script setup>
import {ref} from "vue";
import {ElMessage} from "element-plus";
import '../../../public/gt.js'
import axios from "axios";
import qs from "qs";
import router from "@/router";

const user = ref({phoneNumber:'',password:''});
const login = ()=>{
  // let data = qs.stringify(user.value)
  // axios.post('http://localhost:17090/passport/login',data)
  // .then((response) =>{
  //   if(response.data.code==20001){
  //     ElMessage.success("登录成功!");
  //   }else {
  //     ElMessage.error(response.data.msg);
  //   }
  // })
}

const initValidate = async () => {
  let getValidateURL = `https://www.geetest.com/demo/gt/register-click?t=${(new Date()).getTime()}`
  let getValidateOptions = { method: 'GET' }
  let getValidateData = await fetch(getValidateURL, getValidateOptions)
  getValidateData = await getValidateData.json()
  if(getValidateData.success) {
    console.log("Captcha Init")
    initGeetest({
      gt: getValidateData.gt,
      challenge: getValidateData.challenge,
      new_captcha: getValidateData.new_captcha,
      offline: !getValidateData.success,
      product: "bind",
      width: "100%",
      lang: "en"
    }, function (captchaObj) {
      captchaObj.onReady(function () {
        console.log("Captcha Ready")
        captchaObj.verify();
      }).onSuccess(function () {
        console.log("Captcha Success")
        ElMessage.success("提交成功")
      });
    });
  }
}
</script>
<style scoped>
#main-div {
  height: 500px;
  background-image: url('/public/loginbg.gif');
  /*常用于设置封面*/
  background-size: cover;
  background-position: center;
}
</style>